﻿if ($.Manager == null)
	$.Manager = {};

$.Manager.getList = function()
{
	$.ajaxNet(
		"/manager/manager/managermethod.aspx?_vb=GetList",
		{
			PageNo : $("div.pager").pager("option", "currentPageNo"),
			PageSize : $("div.pager").pager("option", "pageSize")
		}, function(results, context)
		{
			$("table.managerList tbody").html(results[0]);
			$("div.pager").pager("update", results[1]);
		});
};

$.Manager.showInputForm = function(manageEntity) {
	if (typeof(manageEntity) == "undefined")
	{
		$("div.inputForm")
			.find("input.managerSN").val("0").end()
			.find("input.managerId").val("").removeAttr("disabled").end()
			.find("input.managerPassword").val("").end()
			.find("input.managerName").val("").end()
			.show();
	}
	else
	{
		$("div.inputForm")
			.find("input.managerSN").val(manageEntity.n4ManagerSN).end()
			.find("input.managerId").val(manageEntity.strManagerID).attr("disabled", "disabled").end()
			.find("input.managerPassword").val("********").end()
			.find("input.managerName").val(manageEntity.strManagerName).end()
			.show();
	}
}

$.Manager.cancelInputForm = function() {
	$("div.inputForm").hide();
}

$.Manager.submitInputForm = function() {
	var n4ManagerSN = $("div.inputForm input.managerSN").val();
	var strManagerID = $("div.inputForm input.managerId").val();
	var strManagerPass = $("div.inputForm input.managerPassword").val();
	var strManagerName = $("div.inputForm input.managerName").val();

	if (strManagerPass == "********")
		strManagerPass = "";
		
	if (n4ManagerSN > 0)
	{
		$("div.inputForm").ajaxNet(
			"/manager/manager/managermethod.aspx?_vb=Modify",
			{
				"ManagerSN" : n4ManagerSN,
				"ManagerPassword" : strManagerPass,
				"ManagerName" : strManagerName
			}, function(results, context)
			{
				$("div.inputForm").hide();
				alert('수정되었습니다.');
				$.Manager.getList();
			});
	}
	else
	{
		$("div.inputForm").ajaxNet(
			"/manager/manager/managermethod.aspx?_vb=Create",
			{
				"ManagerID" : strManagerID,
				"ManagerPassword" : strManagerPass,
				"ManagerName" : strManagerName
			}, function(results, context)
			{
				$("div.inputForm").hide();
				alert('추가되었습니다.');
				$("div.pager").pager("pageNo", 1);
				$.Manager.getList();
			});
	}
}

$.Manager.modify = function(elem) {
	var manageEntity = $(elem).closest("tr").tagdata();
	
	$.Manager.showInputForm(manageEntity);
};

$.Manager.remove = function(elem) {
	var manageEntity = $(elem).closest("tr").tagdata();

	$("table.managerList").ajaxNet(
		"/manager/manager/managermethod.aspx?_vb=Remove",
		{
			"ManagerSN" : manageEntity.n4ManagerSN
		}, function(results, context)
		{
			alert('삭제되었습니다.');
			$.Manager.getList();
			
		});
};

$.Manager.managerAdd = function(elem) {
	var manageEntity = $(elem).closest("tr").tagdata();
	$("table.managerList").ajaxNet(
		"/manager/manager/managermethod.aspx?_vb=Manager",
		{
			"ManagerSN" : manageEntity.n4ManagerSN
		,	"isManager" : 1
		}, function(results, context)
		{
			alert('변경되었습니다.');
			$.Manager.getList();
			
		});
};

$.Manager.managerReset = function(elem) {
	var manageEntity = $(elem).closest("tr").tagdata();
	$("table.managerList").ajaxNet(
		"/manager/manager/managermethod.aspx?_vb=Manager",
		{
			"ManagerSN" : manageEntity.n4ManagerSN
		,	"isManager" : 0
		}, function(results, context)
		{
			alert('변경되었습니다.');
			$.Manager.getList();
			
		});
};